Airports and Seaports DashboardΒΆ
IntroductionΒΆ
Transportation plays a crucial role in every sphere of human life, with Air and Sea travel revolutionizing the development of modern world. Airports and Seaports work as gate-keepers for global connectivity, radically improving the quality of life in economic, social and healthcare spheres. For this Assignment, I choose to map these pivotal elements of the world, to understand them with respect to each country and explore them visually on the map. Understanding the distribution across the countries and regions can play an important role in real world implementation of tourism and trade.
import folium
from folium.plugins import MarkerCluster, Fullscreen, MeasureControl, MousePosition, MiniMap
from folium import plugins
from branca.element import Figure
import geojson
import pandas as pd
import geopandas as gpd
from shapely.geometry import Point
import panel as pn
import plotly.express as px
import matplotlib.pyplot as plt
import contextily as ctx
import numpy as np
from bokeh.resources import INLINE
airport_data = gpd.read_file("airports_world.geojson")
airport_data = airport_data.dropna(subset=['Country_Name'])
seaport_data = gpd.read_file("ports_world.geojson")
seaport_data = seaport_data.dropna(subset=['Country_Name'])
Dataset and Data Cleaning:ΒΆ
The data set for world Airports and Seaports was downloaded online and involved an extensive process of cleaning the fields and values to obtain the required data in a geojson format. For the Airports dataset, data cleaning and preprocessing involved discarding the fields not required and creating a new field of Country_Name for the corresponding Country Code. To achieve this, I used a different dataset with Country code and corresponding Name to create a lookup and generate the final geojson file [airports_world.geojson] imported in this. The same process was repeated for the Seaports dataset to generate the final geojson file [ports_world.geojson] used in the assignment.
print(airport_data.columns)
Index(['code', 'time_zone_id', 'name', 'country_id', 'Country_Name',
'geometry'],
dtype='object')
print(seaport_data.columns)
Index(['PORT_NAME', 'COUNTRY', 'LATITUDE', 'LONGITUDE', 'GlobalID',
'Country_Name', 'geometry'],
dtype='object')
# Extract latitude and longitude data for airports and seaports
airport_latitudes = airport_data['geometry'].y
airport_longitudes = airport_data['geometry'].x
seaport_latitudes = seaport_data['LATITUDE']
seaport_longitudes = seaport_data['LONGITUDE']
# Create the scatter plot
plt.figure(figsize=(10, 6))
# Plot airports and seaports
plt.scatter(airport_longitudes, airport_latitudes, color='#FF6347', label='Airports', marker='+', s=8)
plt.scatter(seaport_longitudes, seaport_latitudes, color='#4682B4', label='Seaports',marker='x', s=8)
plt.xlabel('Longitude')
plt.ylabel('Latitude')
plt.title('Locations of Airports and Seaports')
plt.legend()
plt.grid(True)
# Get current axes
ax = plt.gca()
# Overlay base map
source = ctx.providers.CartoDB.Voyager
ctx.add_basemap(ax, crs='EPSG:4326', source=source)
plt.show()
Static Map:ΒΆ
A simple static map with a scatter plot is created to understand the distribution of the Airports and Seaports across the world. This map gives us insight on the general location and clustering of Airports and Seaports for the countries. We can observe that the countries along the coastline and access to Waterways have higher number of Seaports and Countries located in central mainland have only Airports and very few Seaports. This data can give the observer an overview understanding of the main mode of transportation for the countries.
#Function to display the Airport Name
def popup_aiports(row):
html = "<h4>{}</h4>".format(row['name'])
html += "<p>Country: {}</p>".format(row['Country_Name'])
return html
#Function to display the Seaport Name
def popup_seaports(row):
html = "<h4>{}</h4>".format(row['PORT_NAME'])
html += "<p>Country: {}</p>".format(row['Country_Name'])
return html
#Interactive map
Europe = (50, 10)
# Create the map object with a specific tile layer
map = folium.Map(location=Europe, zoom_start=5)
#Mapbox
mapbox_user = 'phalguni-venkatesh'
style_id1 = 'clvo47yaw00dm01qu6298exo2'
mapbox_token = ''
# Add multiple tile layers to the map
tiles1 = 'https://api.mapbox.com/styles/v1/'+mapbox_user+'/'+style_id1+'/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1IjoicGhhbGd1bmktdmVua2F0ZXNoIiwiYSI6ImNsc3ZxYzAzZTFrZnIybHFrdHp1dGlrMmUifQ.ukhr8m9vHBV7n_xJXWFTMA'+mapbox_token
folium.TileLayer('cartodbpositron').add_to(map)
folium.TileLayer('openstreetmap').add_to(map)
folium.TileLayer(tiles1, name='Custom Mapbox Layer', attr='Mapbox').add_to(map) # Set custom name and attribution
# Adding markers and other features
marker_cluster = MarkerCluster().add_to(map)
Fullscreen().add_to(map)
plugins.Geocoder().add_to(map)
folium.LayerControl().add_to(map)
MeasureControl().add_to(map)
MousePosition().add_to(map)
MiniMap(tile_layer="OpenStreetMap").add_to(map)
<folium.plugins.minimap.MiniMap at 0x2ab8c887bd0>
Features included in Interactive mapΒΆ
Below are some of the additional features included in the map to be more user-friendly:
- Marker cluster: This allows better readability with large data, especially when dealing with vast number of markers plotted across the world.
- Fullscreen: This makes it easier for the User to read and interact with the map by enabling Full screen mode.
- Measure control: This enhances the interactivity with the map, allowing user to measure the linear distance and area over the selected points/region. This can allow the user to analyse the distance between the markers, like the closest Airport to a specific Seaport.
- Mouse position: This feature displays the geolocation (latitude and longitude) of the movement of the cursor on the map.
- Mini map: This creates miniature map embedded providing the user with the over view of the map and allowing the user to interact with the Main map as well. This functionality can help when data markers are plotted across an enormous region, like all countries of the world.
- Geo coder: This is a simple feature of allowing the user to look for a specific location in the search box and hence make finding specific Airport/Seaport easier for the user.
#Add folium markers for airports
for index, row in airport_data.iterrows():
popup_content = popup_aiports(row)
folium.Marker(location=[row.geometry.y, row.geometry.x], popup=popup_content,icon=folium.Icon(color="red", icon="circle", prefix='fa')).add_to(marker_cluster)
#Add folium markers for seaports
for index, row in seaport_data.iterrows():
popup_content = popup_seaports(row)
folium.Marker(location=[row.geometry.y, row.geometry.x], popup=popup_content,icon=folium.Icon(color="blue", icon="circle", prefix='fa')).add_to(marker_cluster)
map